using System;using System.Collections;namespace Zeus.Data{	/// <summary>	/// The SimpleRow class represents a single row of a SimpleTable	/// </summary>	public class SimpleRow	{		private ArrayList items;		private SimpleTable table;		internal SimpleRow(SimpleTable table)		{			this.table = table;			this.items = new ArrayList(new object[table.Columns.Count]);			this.table.columns.AlterColumn += new SimpleColumnEventHandler(columns_AlterColumn);		}		internal void columns_AlterColumn(ColumnEventType type, int index)		{			switch (type) 			{				case ColumnEventType.Add:					this.items.Add(null);					break;				case ColumnEventType.Insert:					this.items.Insert(index, null);					break;				case ColumnEventType.Remove:					this.items.RemoveAt(index);					break;				case ColumnEventType.Clear:					this.items.Clear();					break;			}		}		/// <summary>
		/// Returns an item from the SimpleRow by colum name
		/// </summary>
		/// <param name="columnName">The columnName to pull the data from</param>
		/// <returns>the row data from the specified column</returns>		public object ByName(string columnName) 		{			object tmp = this[columnName];
			if (tmp == null)			{				return string.Empty;			}			else 			{				return tmp;			}		}
		/// <summary>
		/// Returns an item from the SimpleRow by colum index
		/// </summary>
		/// <param name="rowIndex">The column Index to pull the data from</param>
		/// <returns>the row data from the specified column</returns>
		public object ByIndex(int columnIndex) 		{			object tmp = this[columnIndex];			if (tmp == null)			{				return "";			}			else 			{				return tmp;			}		}		/// <summary>
		/// Returns an item from the SimpleRow by colum index or name
		/// </summary>		public object this[object columnIndexOrName] 		{			get 			{				int columnIndex;				if (columnIndexOrName is String) 				{					columnIndex = this.table.columns.IndexOf(columnIndexOrName.ToString());					if (columnIndex >= 0) 					{						return items[columnIndex];					}					else 					{						throw new IndexOutOfRangeException("Column " + columnIndexOrName.ToString() + " was not found in this SimpleTable.");					}				}				else if (columnIndexOrName is Int32)				{					columnIndex = (int)columnIndexOrName;
					if ((columnIndex >= 0) && (columnIndex < items.Count)) 					{						return items[columnIndex];					}					else 					{						throw new IndexOutOfRangeException("Index " + columnIndex + " is out of range. This SimpleTable has a column length of " + items.Count + ".");					}				}				else if (columnIndexOrName is SimpleColumn)				{					SimpleColumn col = columnIndexOrName as SimpleColumn;
					columnIndex = table.Columns.IndexOf(col.Name);
					if (columnIndex >= 0) 					{						return items[columnIndex];					}					else 					{						throw new IndexOutOfRangeException("Column [" + col.Name + "] is out of range. This SimpleTable does not contain this column.");					}				}				else 				{					throw new Exception("The indexer must be an Int32, string, or a SimpleColumn");				}			}			set 			{				int columnIndex;				if (columnIndexOrName is String) 				{					columnIndex = this.table.columns.IndexOf(columnIndexOrName.ToString());
					if (columnIndex >= 0) 					{						items[columnIndex] = value;					}					else 					{						throw new IndexOutOfRangeException("Column " + columnIndexOrName.ToString() + " was not found in this SimpleTable.");					}				}				else if (columnIndexOrName is Int32)				{					columnIndex = (int)columnIndexOrName;
					if ((columnIndex >= 0) && (columnIndex < items.Count)) 					{						items[columnIndex] = value;					}					else 					{						throw new IndexOutOfRangeException("Index " + columnIndex + " is out of range. This SimpleTable has a column length of " + items.Count + ".");					}				}				else if (columnIndexOrName is SimpleColumn)				{					SimpleColumn col = columnIndexOrName as SimpleColumn;
					columnIndex = table.Columns.IndexOf(col.Name);
					if (columnIndex >= 0) 					{						items[columnIndex] = value;					}					else 					{						throw new IndexOutOfRangeException("Column [" + col.Name + "] is out of range. This SimpleTable does not contain this column.");					}				}				else 				{					throw new Exception("The indexer must be an Int32, a SimpleColumn, or a string");				}			}		}	}}